<#include "../common/header.htm">
<div id="hidebox" style="height:100%;width:100%">
    <div class="box-body table-responsive">
        <!--<span id="spantitle" class="title"></span>-->
        <form id="caseManageform" method="post" class="form-horizontal" >
            <div class="form-group">
                <label for="caseTime" class="col-sm-3 control-label">案发时间：</label>
                <div class="col-sm-6">
                    <input id="caseTime" name="case_time">
                </div>
            </div>
            <div class="form-group">
                <label for="caseAddress" class="col-sm-3 control-label"><span class="casestar">*</span>案发辖区：</label>
                <div class="col-sm-8 casexiaqu">
                    <input id="caseAddress" name="case_region" class="form-control easyui-validatebox" data-options="required:true,validType:['length[1,100]']"/>
                </div>
            </div>
            <div class="form-group">
                <label for="caseType" class="col-sm-3 control-label">案件类型：</label>
                <div class="col-sm-8 casetypec">
                </div>
            </div>
            <div class="form-group">
                <label for="caseName" class="col-sm-3 control-label"><span class="casestar">*</span>案件名称：</label>
                <div class="col-sm-8">
                    <input name="case_name" class="form-control easyui-validatebox" id="caseName" data-options="required:true,validType:['length[1,50]']"/>
                </div>
            </div>
            <div class="form-group">
                <label for="casePerson" class="col-sm-3 control-label">涉案人员类型：</label>
                <div class="col-sm-8 casetypec">

                </div>
            </div>
            <div class="form-group">
                <label for="personName" class="col-sm-3 control-label">涉案人员姓名：</label>
                <div class="col-sm-6">
                    <input name="case_victim" type="text" class="form-control" id="personName" data-options="validType:['length[1,100]']"/>
                </div>
                <sapn class="caseperfen">多个人员用";"分隔</sapn>
            </div>
            <div class="form-group">
                <label for="caseAuthority" class="col-sm-3 control-label">案件权限：</label>
                <div class="col-sm-8">
                    <input name="case_authority" type="radio" id="caseAuthority" value="0"><span class="casetypespan">公开</span>
                    <input name="case_authority" type="radio" id="caseAuthority" value="1" ><span class="casetypespan">私有</span>
                </div>
            </div>
            <div class="form-group">
                <label for="caseRemark" class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="case_remark" id="caseRemark" style="width: 666px;height: 100px;" data-options="validType:['length[1,1000]']"></textarea>
                </div>
            </div>
            <input name="id" type="hidden" class="form-control" id="caseId" >
            <div class="form-group bill-buttonarea"  style="text-align: center;">
                <input type="button" class="btn btn-primary" onclick="submission();" value="提交" />
            </div>
        </form>
    </div>
</div>
<script>
    var url = '';
    var backUrl='';
    $(function() {
        var curr_time = new Date();
        /** 回去传值 **/
        var dialog = top.dialog.get(window);
        var data = dialog.data; // 获取对话框传递过来的数据
        backUrl = data.backUrl;
        if (data.caseId){
            $.ajax({
                url:'${ctx}/casemanage/'+data.caseId,
                type: 'get',
                async:false,
                dataType:'json',
                success:function (obj) {
                    curr_time = new Date(obj.data.case_time);
                    $('#caseTime').datebox({
                        required:false,
                        editable:false,
                        width:'45%',
                    }).datebox("setValue",formatDate(curr_time,'yyyy-MM-dd'));
                    $.ajax({
                        url: '${ctx}/persontype/allpersontype',
                        type: 'get',
                        async:false,
                        dataType:'json',
                        success:function (data) {
                            var htm = '';
                            console.log(data)
                            $.each(data,function (i,n) {
                                htm += '<input name="person_type" type="radio" id="casePerson" value="'+n.id+'" ';
                                if (obj.data.person_type==n.id) {
                                    htm += ' checked = "true" '
                                }
                                htm +=   ' ><span class="casetypespan">'+n.personType+'</span>';
                            })
                            $("label[for=\"casePerson\"]").next().html(htm);
                        }
                    });
                    $.ajax({
                        url: '${ctx}/casetype/allcasetype',
                        type: 'get',
                        async:false,
                        dataType:'json',
                        success:function (data) {
                            var htm = '';
                            $.each(data,function (i,n) {
                                htm += '<input name="case_type" xx="'+n.typeName+'" type="radio" id="caseType" value="'+n.id+'" ' ;
                                if (obj.data.case_type==n.id) {
                                    htm += ' checked = "true" '
                                }
                                htm +=  '/><span class="casetypespan">'+n.typeName+'</span>';
                            })
                            $("label[for=\"caseType\"]").next().html(htm);
                        }
                    });
                    $('#caseAddress').val(obj.data.case_region);
                    $('#caseName').val(obj.data.case_name);
                    $('#personName').val(obj.data.case_victim);
                    $('#caseRemark').val(obj.data.case_remark);
                    $('#caseId').val(obj.data.id);
                    $('input[name="case_authority"][value="'+obj.data.case_authority+'"]').attr('checked', 'true');
                }
            })
            url = 'updateCase';
        } else {
            $('#caseTime').datebox({
                required:false,
                editable:false,
                width:'45%',
            }).datebox("setValue",formatDate(curr_time,'yyyy-MM-dd hh:mm:ss'));
            $.ajax({
                url: '${ctx}/persontype/allpersontype',
                type: 'get',
                async:false,
                dataType:'json',
                success:function (data) {
                    var htm = '';
                    $.each(data,function (i,n) {
                        htm += '<input name="person_type" type="radio" id="casePerson" value="'+n.id+'" ><span class="casetypespan">'+n.personType+'</span>';
                    })
                    $("label[for=\"casePerson\"]").next().html(htm);
                }
            });
            $.ajax({
                url: '${ctx}/casetype/allcasetype',
                type: 'get',
                async:false,
                dataType:'json',
                success:function (data) {
                    var htm = '';
                    $.each(data,function (i,n) {
                        htm += '<input name="case_type" xx="'+n.typeName+'" type="radio" class="easyui-validatebox" data-options="required:true" id="caseType" value="'+n.id+'"/><span class="casetypespan">'+n.typeName+'</span>';
                    })
                    $("label[for=\"caseType\"]").next().html(htm);
                }
            });
            $('input[name="case_authority"]:last').attr('checked', 'true');
            url = 'addCase';
        }
        $("input",$("#caseTime").next("span")).blur(function(){
            change();
        });
        $("#caseAddress").blur(function(){
            change();
        });
        $('input[name="case_type"]').change(function(){
            change();
        });$('input[name="case_type"]').next().click(function(){
            change();
        });
        $('input[type="radio"]').next().click(function(){
            $(this).prev().prop('checked',true);
        });
        function change() {
            var caseTime = $('#caseTime').val();
            var caseAddress = $('#caseAddress').val();
            var caseType = $('input[name="case_type"]:checked').attr('xx');
            if (caseType) {
                $("#caseName").val(caseTime + caseAddress + caseType);
            }else {
                $("#caseName").val(caseTime + caseAddress);
            }
        };
    });

    /*编辑*/
	function submission(){
		if(!$("#caseManageform").form('validate')){
			return false;
		}
		var data = $("#caseManageform").serialize();
	    $.ajax({
	        url : "${ctx}/casemanage/"+url,
	        data : data,
	        success : function (data) {
	        	if(data.result = 'success'){
	        		if(backUrl){
	        			window.parent.open(backUrl+data.data.case_uuid, "_self");
	        		}else{
	        	    	window.parent.location.reload();
	        		}
	        	}
	        },
	        error : function() {
	        	toastr.error("保存失败","提示信息");
	        }
	    });
	};


</script>
<style>
    .bill-buttonarea .btn{
        background: #4595ec;
        border-color: transparent;
    }
    .bill-buttonarea .btn:hover{
        background: #3296f1;
    }
    .btn-primary:active:focus{
        background: #0c76d7;
    }
    .casetypespan{
        cursor: pointer;
    }
    #caseRemark{
        border-radius: 4px;
        border: solid 1px #d9d9d9;

    }
    sapn.caseperfen {
        margin-left: 25px;
        height: 34px;
        line-height: 34px;
    }
    .col-sm-8{
        padding-left: 0;
    }
    .col-sm-6{
        padding-left: 0;
    }
    #personName{
        width: 527px;
        height: 34px;
        background-color: #ffffff;
        border-radius: 4px;
        border: solid 1px #d9d9d9;
    }
    input#caseAuthority{
        margin-right: 6px;
    }
    input#casePerson {
        margin-right: 6px;
    }
    span.casetypespan {
        margin-right: 35px;
    }
    input#caseType {
        margin-right: 6px;
    }
    .casetypec{
        margin-top: 5px;
    }
    .form-group {
        margin-bottom: 25px;
    }
    span.casestar {
        color: red;
        font-size: 18px;
        position: absolute;
        right: 86px;
        top: 8px;
        font-weight: 900;
    }
    label.col-sm-3.control-label {
        font-weight: normal;
        color: #000;
    }
    .box-body {
        margin-top: 30px;
    }
    .box-body.table-responsive {
        height: 100%;
    }
    .fixed-table-pagination {
        margin-top: 15px;
    }
    .form-control {
         width: 666px;
         height: 34px;
        line-height: 25px;
        background: #fff;
        border-color: #d9d9d9;
        border-radius: 4px;
    }
</style>
</body>
</html>
